<?php
/**
 * This file contains the class PersonNoticesView which provides
 * all of the text requirements for the person notices page
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 */
/**
 * This class provides the text for PersonNotices
 *
 * @copyright  2009 A Memory Tree
 * @license    A Memory Tree License
 */
class PersonNoticesView
{
    /**
     * A place to store pre-prepared messages
     *
     * @var array[string]string
     */
    private $_text;
    /**
      * The html class that provides helpers to display the text
     *
     * @var Html
     */
    private $_html;
    /**
     * Builds the list of text messages
     * 
     * @return void
     * @param Html &$html
     */
    function __construct(&$html)
    {
        $this->_html = $html;
        $this->_text['test'] = 'A test message';
    }
    /**
     * Return the text that's associated with the given name
     * 
     * @return string
     * @param string $name
     */
    function text($name)
    {
        return $this->_text[$name];
    }
    function personHeader($surname, $firstNames)
    {
    return <<< EOT
                <h2>Published Notices for $firstNames $surname</h2>
EOT;
    }
    /**
     * Show the person info
     *
     * @return string
     * @param int $personId
     * @param string $surname
     * @param string $firstNames
     * @param string $akaName
     * @param string $neeAndFormerName
     * @param string $deathDate
     * @param string $age
     * @param string $publishedNotices
     * @param string $country
     */
    function personInfo($personId, $surname, $firstNames, $akaName, $neeAndFormerName, $deathDate, $age, $publishedNotices, $country)
    {
        $html = $this->_html;
        $personId = intval($personId);
        $surname = $html->text($surname);
        $firstNames = $html->text($firstNames);
        $neeAndFormerName = $neeAndFormerName;
        $deathDate = $html->text($deathDate);
        $age = $html->text($age);
        $publishedNotices = $html->text($publishedNotices);
        $country = $html->text($country);
        return <<< EOT
                <p class="results_name">
                    <a href="remembrance.php?personid=$personId" class="mainname">$surname, $firstNames</a>.
                    $akaName
                </p>
                $neeAndFormerName
                <p>$deathDate$age</p>
                <p>Published Notices ($publishedNotices)</p>
                <p class="left">Remembrance Page Open <a href="remembrance.php?personid=$personId">sign page or view entries</a></p>
                <p class="right">$country&nbsp;</p>
EOT;
    }
    /**
     * A single death notice
     *
     * @return string
     * @param string $newspaper
     * @param string $url
     * @param $date
     */
    function deathNotice($newspaper, $url, $date)
    {
        $html = $this->_html;
        $newspaper = $html->text($newspaper);
        $url = $html->text($url);
        $date = $html->text($date);
        return <<< EOT
                <tr>
                    <td>
                        <a href="$url" title="View obituaries">$newspaper</a>
                    </td>
                    <td style="float:left; padding-left: 1em;">$date</td>
                <tr>

EOT;
    }
    /**
     * Introduction for the notices
     *
     * @return string
     */
    function noticeIntro() {
        return <<< EOT
                    <p>Clicking on the newspaper below will take you to their web site. Death notices aren't always available on these web sites. However, we are able to provide summaries of all notices.</p> 

EOT;
    }
    /**
     * The notice listings
     *
     * @return string
     * @param string $noticeListings
     */
    function noticeListings($noticeListings) {
        return <<< EOT
                    <table style="margin: 0.5em 0">
                        $noticeListings
                    </table>

EOT;
    }
    /**
     * Info about ordering a summary of notices
     *
     * @return string
     */
    function orderSummary()
    {
        return <<< EOT
        <style type="text/css">
        a.overlay {background: url(/images/assets/sampleNoticeSummarySprite.png); display: block;  width: 200px; height: 324px; }
        a.overlay:hover {background: url(/images/assets/sampleNoticeSummarySprite.png) right; display: block;  width: 200px; height: 324px; }
        a.overlay img { display: none; }
        </style>
        <p><a class="overlay" href="/sampleNoticeSummary.php"><img src="/images/assets/sampleNoticeSummaryThumb.png" width="200" height="324" alt=""></a></p>
EOT;
    }
    /**
     * Order form to order a summary of notices
     *
     * @return string
     */
    function orderForm($personId, $fullName, $publicationList, $price, $errorMessages)
    {
        $html = $this->_html;
        $fullName = $html->text($fullName);
        $formattedPrice = number_format($price, 2);
        $publications = '';
        $count = 0;
        foreach ($publicationList as $publication => $number) {
            $checked = '';
            for ($i = 0; $i < count($_GET['publication']); $i++) {
                $getPublication = urldecode($_GET['publication'][$i]);
                if ($getPublication === $publication) {
                    $checked = ' checked="checked"';
                }
            }
            $publications .= <<< EOT
            <p class="checkbox">
                <input type="checkbox" id="publication$count" name="publication[]" value="$publication"$checked>
                <label for="publication$count">$publication ($number)</label>
                <span class="price">$$formattedPrice</span>
            </p>

EOT;
            $count++;
        }
        $emailValue = $_GET['email'];
        if (!empty($emailValue)) {
            $emailValue = ' value="'.$html->text($emailValue).'"';
        }
        $confirmEmailValue = $_GET['confirmEmail'];
        if (!empty($confirmEmailValue)) {
            $confirmEmailValue = ' value="'.$html->text($confirmEmailValue).'"';
        }
        $publicationError = $errorMessages['publication'];
        $emailProvidedError = $errorMessages['email'];
        $emailMatchError = $errorMessages['confirm'];
        $form = <<< EOT
            <h2>Order a Summary for <br>$fullName</h2>
            <form method="GET" action="orderPublicationSummary.php">
                <input type="hidden" name="personid" value="$personId">
                <fieldset>
                    <legend>Publications</legend>
$publicationError
$publications
                </fieldset>
$emailProvidedError
                <p>
                    <label for="email">Your email</label>
                    <input type="text" id="email" name="email"$emailValue>
                </p>
$emailMatchError
                <p>
                    <label for="confirmEmail">Confim your email</label>
                    <input type="text" id="confirmEmail" name="confirmEmail"$confirmEmailValue>
                </p>
                <p>Please allow up to 24 hours for one of our people to compile your summary.</p>
                <input type="submit" name="Submit" value="Checkout" class="button" style="float:right">
            </form>

EOT;
    return $form;
    }
    /**
     * Show the notice page
     *
     * @return string
     * @param string $personInfo
     * @param string $noticeListings
     * @param string $noticeOrder
     */
    function noticePage($personInfo, $noticeIntro, $noticeListings, $noticeSummary, $noticeOrder)
    {
        $personHeader = $personInfo['header'];
        $personDetails = $personInfo['details'];
        return <<< EOT
        <style type="text/css">
        /* id attributes for contentarea and centerbar are to force the form to have more Specificity than that defined in style.css */
    #contentarea #centerbar form p { margin: 0.5em 0; }
    #contentarea #centerbar .resultinfo2 p { margin: 0; }
    #contentarea #centerbar form fieldset { padding: 0.5em 0; }
    #orderNotice label { display: block; }
    .checkbox { text-align: right; }
    .checkbox input { float: left; margin-right: 0.5em }
    .checkbox label { float: left; }
    #orderNotice .error { color: red; }
    #orderNotice #email { width: 100%; }
    #orderNotice #confirmEmail { width: 100%; }
    
        </style>
        <div id="centerbar">
            <ul id="searchresults">
                <li class="header">$personHeader</li>
                <li class="resultinfo2">$personDetails</li>
            </ul>
            $noticeIntro
            <div id="orderNotice">
                $noticeOrder
            </div>
            <div class="noticeListings">
                <h2>Newspapers</h2>
                $noticeListings
            </div>
            <hr>
            <h2>Example Notice Summary</h2>
            $noticeSummary
        </div>
        <script type="text/javascript" src="/js/personNotices.js"> </script>

EOT;
    }
}
?>